//
//  InstitutionalAppointmentTopView.swift
//  Venus
//
//  Created by point on 2018/10/9.
//  Copyright © 2018年 zhaowang. All rights reserved.
//

import UIKit

protocol InstitutionalAppointmentTopViewDelegate:class {
    func clickTopViewItem(index:Int)
}

class InstitutionalAppointmentTopView: UIView {
    
    weak var dalegate:InstitutionalAppointmentTopViewDelegate?
    
    fileprivate lazy var leftBtn:UIButton =  UIButton(type: .custom)
    fileprivate lazy var rightBtn:UIButton =  UIButton(type: .custom)
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}


// MARK: - 交互
extension InstitutionalAppointmentTopView {
    @objc func clickLeftBtn(btn:UIButton) {
        leftBtn.isSelected = true
        rightBtn.isSelected = false
        dalegate?.clickTopViewItem(index: 0)
    }
    
    @objc func clickRightBtn(btn:UIButton) {
        leftBtn.isSelected = false
        rightBtn.isSelected = true
        dalegate?.clickTopViewItem(index: 1)
    }
}

extension InstitutionalAppointmentTopView {
    func setupUI() {
        backgroundColor = nC1
        addSubview(leftBtn)
        addSubview(rightBtn)
        leftBtn.snp.makeConstraints { (make) in
            make.height.equalTo(50)
            make.width.equalTo((LayoutCommon.width - 0.5) / 2)
            make.left.equalToSuperview()
            make.top.equalToSuperview()
        }
        leftBtn.setTitle("最新预约", for: .normal)
        leftBtn.setTitleColor(UIColor.init(hex: "17bbfe"), for: .selected)
        leftBtn.setTitleColor(UIColor.init(hex: "333333"), for: .normal)
        leftBtn.backgroundColor = UIColor.white
        leftBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        leftBtn.isSelected = true
        rightBtn.snp.makeConstraints { (make) in
            make.height.equalTo(50)
            make.width.equalTo((LayoutCommon.width - 0.5) / 2)
            make.right.equalToSuperview()
            make.top.equalToSuperview()
        }
        rightBtn.setTitle("历史预约", for: .normal)
        rightBtn.setTitleColor(UIColor.init(hex: "17bbfe"), for: .selected)
        rightBtn.setTitleColor(UIColor.init(hex: "333333"), for: .normal)
        rightBtn.backgroundColor = UIColor.white
        rightBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        rightBtn.addTarget(self, action: #selector(clickRightBtn(btn:)), for: .touchUpInside)
        leftBtn.addTarget(self, action: #selector(clickLeftBtn(btn:)), for: .touchUpInside)
    }
}
